import sys
from PyQt5.QtWidgets import QApplication, QWidget
from PyQt5.Qt import QLineEdit, QPushButton, QLabel, QObject


'''
   del obj2 只能删除栈中的对象，不能堆中的对象，相当于切断联系，不能真正的删除
   obj2.deleteLater() 1.删除栈中的对象，真正的删除 2.在整段代码结束之后，才会执行这个方法
'''
class Window(QWidget):
    def __init__(self):
        super().__init__()
        self.resize(600, 400)
        self.setWindowTitle("垃圾识别")
        self.move(100, 100)

        obj1 = QObject()
        print(obj1)
        obj2 = QObject()
        obj3 = QObject()
        obj4 = QObject()
        obj1.destroyed.connect(lambda:print('obj1被释放'))
        obj1.deleteLater()
        print(obj1)

        label1 = QLabel(self)
        label1.setText('label1')
        label1.move(50,50)
        label1.setStyleSheet('''
        background-color:red;
        color:#ffffff;
        ''')

        label2 = QLabel(self)
        label2.setText('label1')
        label2.move(50, 100)
        label2.setStyleSheet('''
          background-color:green;
          color:#ffffff;
          ''')
        # del label1
        label1.deleteLater()



if __name__ == '__main__':
    app = QApplication(sys.argv)
    w = Window()


    w.show()
    sys.exit(app.exec_())

